﻿using System;
using System.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Configuration;
using System.ServiceModel.Description;

namespace SsoaFramework.Core.Behaviors
{
    class UpdateRoutingBehavior : BehaviorExtensionElement, IServiceBehavior
    {
        private readonly RoutingTable routingTable;

        public UpdateRoutingBehavior(RoutingTable routingTable)
        {
            this.routingTable = routingTable;
        }

        public void ApplyDispatchBehavior(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
            serviceHostBase.Extensions.Add(routingTable);
        }

        #region Not used
        protected override object CreateBehavior()
        {
            return new UpdateRoutingBehavior(routingTable);
        }
        public override Type BehaviorType
        {
            get { return typeof(UpdateRoutingBehavior); }
        }

        public void Validate(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase)
        {
        }

        public void AddBindingParameters(ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters)
        {
        }
        #endregion
    }
}
